Option Strict On
Option Explicit On 

Imports System.Windows.Forms

''' -----------------------------------------------------------------------------
''' Project	 : IPDataControl
''' Class	 : Core.IPDataControl.DESmartTextBox
''' 
''' -----------------------------------------------------------------------------
''' <summary>
''' Smart textbox for DEMode
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' 	[csung]	3/15/2005	Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class DESmartTextBox

#Region "members"
    Private WithEvents m_txt_de_form_textbox As TextBox
    Private WithEvents m_txtBox As New TextBox
    Private m_enabled As Boolean = True
    Private m_state_notifier As I_DEStateNotifier
    Private m_b_has_been_disabled As Boolean
#End Region

#Region "PUBLIC"
    Public Sub New(ByVal i_txtbox As TextBox)
        m_b_has_been_disabled = Not i_txtbox.Enabled
        If m_b_has_been_disabled Then Exit Sub

        m_txt_de_form_textbox = i_txtbox
        i_txtbox.Parent.Controls.Add(m_txtBox)
        m_txtBox.Visible = False

        m_txtBox.PasswordChar = i_txtbox.PasswordChar
        m_txtBox.Multiline = i_txtbox.Multiline
        m_txtBox.BackColor = System.Drawing.Color.White
        m_txtBox.ForeColor = System.Drawing.Color.Black
        m_txtBox.Font = i_txtbox.Font
        m_txtBox.SendToBack()
        m_txtBox.Top = m_txt_de_form_textbox.Top
        m_txtBox.Left = m_txt_de_form_textbox.Left
        m_txtBox.Width = m_txt_de_form_textbox.Width
        m_txtBox.TextAlign = m_txt_de_form_textbox.TextAlign
    End Sub

    Public Sub New(ByVal i_txtbox As TextBox, ByVal i_de_state_notifier As I_DEStateNotifier)
        m_b_has_been_disabled = Not i_txtbox.Enabled
        If m_b_has_been_disabled Then Exit Sub
        m_txt_de_form_textbox = i_txtbox

        i_txtbox.Parent.Controls.Add(m_txtBox)
        m_txtBox.Visible = False

        m_txtBox.PasswordChar = i_txtbox.PasswordChar
        m_txtBox.Multiline = i_txtbox.Multiline
        m_txtBox.BackColor = System.Drawing.Color.White
        m_txtBox.ForeColor = System.Drawing.Color.Black
        m_txtBox.Font = i_txtbox.Font
        m_txtBox.SendToBack()
        m_txtBox.Top = m_txt_de_form_textbox.Top
        m_txtBox.Left = m_txt_de_form_textbox.Left
        m_txtBox.Width = m_txt_de_form_textbox.Width
        m_txtBox.Height = m_txt_de_form_textbox.Height
        m_txtBox.TextAlign = m_txt_de_form_textbox.TextAlign
        m_state_notifier = i_de_state_notifier
    End Sub

    Public Property Enabled() As Boolean
        Get
            Return m_enabled
        End Get
        Set(ByVal Value As Boolean)
            If m_b_has_been_disabled Then Exit Property
            m_enabled = Value
            If m_enabled Then
                set_enabled_mode()
            Else
                set_disabled_mode()
            End If
        End Set
    End Property

    Public Property Text() As String
        Get
            Return m_txt_de_form_textbox.Text
        End Get
        Set(ByVal Value As String)
            m_txt_de_form_textbox.Text = Value
        End Set
    End Property
#End Region


#Region "PRIVATE"
    Private Sub set_enabled_mode()
        If m_b_has_been_disabled Then Exit Sub
        m_txt_de_form_textbox.Visible = True
        m_txtBox.Visible = False
        m_txtBox.SendToBack()
    End Sub

    Private Sub set_disabled_mode()
        If m_b_has_been_disabled Then Exit Sub
        m_txt_de_form_textbox.Visible = False
        m_txtBox.Text = m_txt_de_form_textbox.Text
        m_txtBox.Visible = True
        m_txtBox.BringToFront()
    End Sub

    Private Sub m_txtBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles m_txtBox.KeyPress
        e.Handled = True
        If Not m_state_notifier Is Nothing Then
            m_state_notifier.displayNotifier()
        End If
    End Sub
#End Region


    Private Sub m_txt_de_form_textbox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_txt_de_form_textbox.TextChanged
        m_txtBox.Text = m_txt_de_form_textbox.Text
    End Sub
End Class
